import React, { Component } from 'react';
import { connect } from 'react-redux';
import { Table, Tag, Space, Button, Popconfirm } from 'antd';
import action from "../../../store/action";
import { Link } from 'react-router-dom';
import { user_table } from '../../view_public/Add_public';



class index extends React.Component {
    constructor() {
        super();

    }
    componentWillMount() {
        this.hadnel_get();
    }
    render() {
        const columns = [
            {
                title: '标准编号',
                dataIndex: 'standardNo',
                key: 'standardNo',
                render: text => <a>{text}</a>,
                width: 230
            },
            {
                title: '标准名称',
                dataIndex: 'name',
                key: 'name',
                width: 120

            },
            {
                title: '适用条件',
                dataIndex: 'temperature',
                key: 'temperature',
                width: 200,
                render: (record, text) => {
                    switch (record) {
                        case 'A':
                            return (<span>常温</span>)
                            break;
                        case 'B':
                            return (<span>高温</span>)
                            break;
                        case 'C':
                            return (<span>低温</span>)
                            break;
                        default:
                            break;
                    }
                }
            },
            {
                title: '创建时间',
                key: 'createTime',
                dataIndex: 'createTime',
                width: 150
            },
            {
                title: '操作',
                key: 'action',
                width: 150,
                render: (text, record, index) => {
                    return <Space size="middle">
                        <Link to='/admin/Stand_edit'><Button type='link' onClick={() => this.handelLink(record)}>编辑</Button></Link>
                        <Popconfirm
                            title="确定要删除吗？"
                            okText="确定"
                            cancelText="取消"
                            onConfirm={() => this.handleDelete(record.standardNo)}
                        >
                            <Button type="link" danger style={{ padding: "0" }}>
                                删除
                          </Button>
                        </Popconfirm>
                    </Space>
                },
            },
        ];
        const data = this.props.standData
        return <div>
            {
                user_table(columns, data)
            }
        </div>
    }
    hadnel_get = () => {
        this.$axios.get('/manager/api/pageGetStandardInfoList/0/9999').then((res) => {

            if (res.status === 1) {
                const { stand_get } = this.props;
                let new_list = {};
                [].push.apply(new_list, res.standardInfoList);
                stand_get(new_list)
            }
        }).catch((err) => {
            console.log(err);
        })
    }
    handelLink = (e) => {
        const { stand_edit } = this.props;
        stand_edit(e)

    }
    handleDelete = (e) => {
        this.$axios.get(`/manager/api/deleteStandardInfo/${e}`).then((res) => {

            this.hadnel_get()
        }).catch((err) => {
            console.log(err);
        })
    }
}
export default connect((state) => ({ ...state.custom }), action.custom)(index);